import Vue from 'vue'
import Router from 'vue-router'
import Home from './views/Home.vue'

Vue.use(Router)

let router = new Router({
  mode: 'history',
  base: process.env.BASE_URL,
  routes: [
    {
      path: '/',
      name: 'home',
      meta: {
        title: '页面home',
      },
      component: Home
    },
    {
      path: '/one',
      name: 'one',
      meta: {
        title: '页面1',
      },
      component: () => import('./views/one.vue')
    },
    {
      path: '/two',
      name: 'two',
      meta: {
        title: '页面2',
      },
      component: () => import('./views/two.vue')
    },
    {
      path: '*',
      component: () => import('./views/noPage.vue')
      // redirect: '/'
    }
  ]
})

router.beforeEach((to, from, next) => {
  window.document.title = to.meta.title;
  next();
})

router.afterEach((to, from, next) => {
  window.scrollTo(0, 0);
})

export default router